nl.justobjects.pushlet.core
Class EventQueue

java.lang.Object
  extended by nl.justobjects.pushlet.core.EventQueue

public class EventQueue
extends java.lang.Object

FIFO queue with guarded suspension. Purpose

Implementation
FIFO queue class implemented with circular array. The enQueue() and deQueue() methods use guarded suspension according to a readers/writers pattern, implemented with java.lang.Object.wait()/notify().

Examples


Version:
$Id: EventQueue.java,v 1.3 2007/11/23 14:33:07 justb Exp $
Author:
Just van den Broecke - Just Objects ©

Constructor Summary
EventQueue()
          Construct queue with default (8) capacity.
EventQueue(int capacity)
          Construct queue with specified capacity.
 
Method Summary
 Event deQueue()
          Get head; if empty wait until something in queue.
 Event deQueue(long maxWaitTime)
          Get head; if empty wait for specified time at max.
 Event[] deQueueAll(long maxWaitTime)
          Get all queued Events.
 boolean enQueue(Event item)
          Put item in queue; waits() indefinitely if queue is full.
 boolean enQueue(Event item, long maxWaitTime)
          Put item in queue; if full wait maxtime.
 int getSize()
           
 boolean isEmpty()
          Is the queue empty ?
 boolean isFull()
          Is the queue full ?
static void main(java.lang.String[] args)
           
static void p(java.lang.String s)
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

EventQueue

public EventQueue()
Construct queue with default (8) capacity.


EventQueue

public EventQueue(int capacity)
Construct queue with specified capacity.

Method Detail

enQueue

public boolean enQueue(Event item)
                throws java.lang.InterruptedException
Put item in queue; waits() indefinitely if queue is full.

Throws:
java.lang.InterruptedException

enQueue

public boolean enQueue(Event item,
                       long maxWaitTime)
                throws java.lang.InterruptedException
Put item in queue; if full wait maxtime.

Throws:
java.lang.InterruptedException

deQueue

public Event deQueue()
              throws java.lang.InterruptedException
Get head; if empty wait until something in queue.

Throws:
java.lang.InterruptedException

deQueue

public Event deQueue(long maxWaitTime)
              throws java.lang.InterruptedException
Get head; if empty wait for specified time at max.

Throws:
java.lang.InterruptedException

deQueueAll

public Event[] deQueueAll(long maxWaitTime)
                   throws java.lang.InterruptedException
Get all queued Events.

Throws:
java.lang.InterruptedException

getSize

public int getSize()

isEmpty

public boolean isEmpty()
Is the queue empty ?


isFull

public boolean isFull()
Is the queue full ?


p

public static void p(java.lang.String s)

main

public static void main(java.lang.String[] args)